package de.jabc.adapter.bio.ebi;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.net.URL;
import java.net.URLConnection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import org.apache.xml.serialize.LineSeparator;
import org.soaplab.clients.ClientConfig;
import org.soaplab.clients.ServiceLocator;
import org.soaplab.clients.SoaplabBaseClient;
import org.soaplab.share.SoaplabException;
import org.soaplab.share.SoaplabMap;

import uk.ac.ebi.webservices.axis1.ClustalW2PhylogenyClient;
import uk.ac.ebi.webservices.axis1.EmbossBacktranambigClient;
import uk.ac.ebi.webservices.axis1.EmbossBacktranseqClient;
import uk.ac.ebi.webservices.axis1.EmbossMatcherClient;
import uk.ac.ebi.webservices.axis1.EmbossNeedleClient;
import uk.ac.ebi.webservices.axis1.EmbossPepinfoClient;
import uk.ac.ebi.webservices.axis1.EmbossPepwindowClient;
import uk.ac.ebi.webservices.axis1.EmbossTranseqClient;
import uk.ac.ebi.webservices.axis1.EmbossWaterClient;
import uk.ac.ebi.webservices.axis1.EmbossStretcherClient;
import uk.ac.ebi.webservices.axis1.EmbossSixpackClient;
import uk.ac.ebi.webservices.axis1.EmbossPepstatsClient;
import uk.ac.ebi.webservices.axis1.NCBIBlastClient;
import uk.ac.ebi.webservices.axis1.PSISearchClient;
import uk.ac.ebi.webservices.axis1.ReadseqClient;
import uk.ac.ebi.webservices.axis1.WUBlastClient;
import uk.ac.ebi.webservices.axis1.ClustalOClient;
import uk.ac.ebi.webservices.axis1.stubs.ncbiblast.InputParameters;
import uk.ac.ebi.webservices.axis1.stubs.readseq.WsParameterDetails;
import de.metaframe.jabc.framework.execution.LightweightExecutionEnvironment;
import de.metaframe.jabc.framework.sib.parameter.foundation.ContextExpressionFoundation;
import de.metaframe.jabc.framework.sib.parameter.foundation.ContextKeyFoundation;

/**
 * This class provides the lightweight service adapters for the SIBs. These
 * service adapters are used to separate the executional code from the SIBs so
 * that code generation using a Pure Generator targeting the Java Standard
 * Edition is possible.
 * 
 * @author anna-lena
 * @version $Revision: 3358 $ $Date: 2008-03-05 10:49:16 +0100 (Wed, 05 Mar
 *          2008) $
 */
public class LightweightServiceAdapter {

	/**
	 * Calls the FetchData operation of the EBI's WSDBFetch web service.
	 * 
	 * @param environment
	 * @param query
	 * @param format
	 * @param style
	 * @param entries
	 * @return
	 */
	public static String callWSDBFetch(
			LightweightExecutionEnvironment environment,
			ContextExpressionFoundation db, ContextExpressionFoundation id,
			ContextExpressionFoundation format,
			ContextExpressionFoundation style, ContextKeyFoundation entry) {

		try {

			// create URL string
			String urlstring = "http://www.ebi.ac.uk/Tools/dbfetch/dbfetch";

			urlstring = urlstring + "/" + environment.evaluate(db);
			urlstring = urlstring + "/" + environment.evaluate(id);

			if (!environment.evaluate(format).equals("")) {
				urlstring = urlstring + "/" + environment.evaluate(format);

				if (!environment.evaluate(style).equals("")) {
					urlstring = urlstring + "?style="
							+ environment.evaluate(style);
				}
			}

			// create URL
			URL url = new URL(urlstring);

			// make connection
			URLConnection urlc = url.openConnection();

			// use post mode
			urlc.setDoOutput(true);
			urlc.setAllowUserInteraction(false);

			// send query
			PrintStream ps = new PrintStream(urlc.getOutputStream());
			ps.close();

			// get result
			BufferedReader br = new BufferedReader(new InputStreamReader(
					urlc.getInputStream()));
			StringBuilder result = new StringBuilder();
			String resultline = null;
			String lineseparator = System.getProperty("line.separator");
			while ((resultline = br.readLine()) != null) {
				result.append(resultline);
				result.append(lineseparator);
			}
			br.close();

			environment.getLocalContext().put(entry, result.toString());
			return Branches.DEFAULT;

		} catch (Exception e) {
			environment.getLocalContext().put("exception", e);
			return Branches.ERROR;
		}

	}

	/**
	 * Searches ArrayExpress for experiments.
	 * 
	 * @param environment
	 * @param keywords
	 * @param accession
	 * @param array
	 * @param ef
	 * @param efv
	 * @param expdesign
	 * @param exptype
	 * @param gxa
	 * @param pmid
	 * @param sa
	 * @param species
	 * @param expandefo
	 * @param resultkey
	 * @return
	 */
	public static String callArrayExpressExperiments(
			LightweightExecutionEnvironment environment,
			ContextExpressionFoundation keywords,
			ContextExpressionFoundation accession,
			ContextExpressionFoundation array, ContextExpressionFoundation ef,
			ContextExpressionFoundation efv,
			ContextExpressionFoundation expdesign,
			ContextExpressionFoundation exptype,
			ContextExpressionFoundation gxa, ContextExpressionFoundation pmid,
			ContextExpressionFoundation sa,
			ContextExpressionFoundation species, boolean expandefo,
			ContextKeyFoundation resultkey) {

		try {

			// create URL string
			String urlstring = "http://www.ebi.ac.uk/arrayexpress/xml/v2/experiments?";

			if (!environment.evaluate(keywords).equals("")) {
				urlstring = urlstring + "keywords="
						+ environment.evaluate(keywords);
			}

			if (!environment.evaluate(accession).equals("")) {
				urlstring = urlstring + "&accession="
						+ environment.evaluate(accession);
			}

			if (!environment.evaluate(array).equals("")) {
				urlstring = urlstring + "&array=" + environment.evaluate(array);
			}

			if (!environment.evaluate(ef).equals("")) {
				urlstring = urlstring + "&ef=" + environment.evaluate(ef);
			}

			if (!environment.evaluate(efv).equals("")) {
				urlstring = urlstring + "&efv=" + environment.evaluate(efv);
			}

			if (!environment.evaluate(expdesign).equals("")) {
				urlstring = urlstring + "&expdesign="
						+ environment.evaluate(expdesign);
			}

			if (!environment.evaluate(exptype).equals("")) {
				urlstring = urlstring + "&exptype="
						+ environment.evaluate(exptype);
			}

			if (!environment.evaluate(gxa).equals("")) {
				urlstring = urlstring + "&gxa=" + environment.evaluate(gxa);
			}

			if (!environment.evaluate(pmid).equals("")) {
				urlstring = urlstring + "&pmid=" + environment.evaluate(pmid);
			}

			if (!environment.evaluate(sa).equals("")) {
				urlstring = urlstring + "&sa=" + environment.evaluate(sa);
			}

			if (!environment.evaluate(species).equals("")) {
				urlstring = urlstring + "&species="
						+ environment.evaluate(species);
			}

			if (expandefo) {
				urlstring = urlstring + "&expandefo=on";
			}

			// create URL
			URL url = new URL(urlstring);

			// make connection
			URLConnection urlc = url.openConnection();

			// use post mode
			urlc.setDoOutput(true);
			urlc.setAllowUserInteraction(false);

			// send query
			PrintStream ps = new PrintStream(urlc.getOutputStream());
			ps.close();

			// get result
			BufferedReader br = new BufferedReader(new InputStreamReader(
					urlc.getInputStream()));
			StringBuilder result = new StringBuilder();
			String resultline = null;
			String lineseparator = System.getProperty("line.separator");
			while ((resultline = br.readLine()) != null) {
				result.append(resultline);
				result.append(lineseparator);
			}
			br.close();

			environment.getLocalContext().put(resultkey, result.toString());
			return Branches.DEFAULT;

		} catch (Exception e) {
			environment.getLocalContext().put("exception", e);
			return Branches.ERROR;
		}

	}

	/**
	 * Searches ArrayExpress for files.
	 * 
	 * @param environment
	 * @param keywords
	 * @param accession
	 * @param array
	 * @param ef
	 * @param efv
	 * @param expdesign
	 * @param exptype
	 * @param gxa
	 * @param pmid
	 * @param sa
	 * @param species
	 * @param expandefo
	 * @param resultkey
	 * @return
	 */
	public static String callArrayExpressFiles(
			LightweightExecutionEnvironment environment,
			ContextExpressionFoundation keywords,
			ContextExpressionFoundation accession,
			ContextExpressionFoundation array, ContextExpressionFoundation ef,
			ContextExpressionFoundation efv,
			ContextExpressionFoundation expdesign,
			ContextExpressionFoundation exptype,
			ContextExpressionFoundation gxa, ContextExpressionFoundation pmid,
			ContextExpressionFoundation sa,
			ContextExpressionFoundation species, boolean expandefo,
			ContextKeyFoundation resultkey) {

		try {

			// create URL string
			String urlstring = "http://www.ebi.ac.uk/arrayexpress/xml/v2/files?";

			if (!environment.evaluate(keywords).equals("")) {
				urlstring = urlstring + "keywords="
						+ environment.evaluate(keywords);
			}

			if (!environment.evaluate(accession).equals("")) {
				urlstring = urlstring + "&accession="
						+ environment.evaluate(accession);
			}

			if (!environment.evaluate(array).equals("")) {
				urlstring = urlstring + "&array=" + environment.evaluate(array);
			}

			if (!environment.evaluate(ef).equals("")) {
				urlstring = urlstring + "&ef=" + environment.evaluate(ef);
			}

			if (!environment.evaluate(efv).equals("")) {
				urlstring = urlstring + "&efv=" + environment.evaluate(efv);
			}

			if (!environment.evaluate(expdesign).equals("")) {
				urlstring = urlstring + "&expdesign="
						+ environment.evaluate(expdesign);
			}

			if (!environment.evaluate(exptype).equals("")) {
				urlstring = urlstring + "&exptype="
						+ environment.evaluate(exptype);
			}

			if (!environment.evaluate(gxa).equals("")) {
				urlstring = urlstring + "&gxa=" + environment.evaluate(gxa);
			}

			if (!environment.evaluate(pmid).equals("")) {
				urlstring = urlstring + "&pmid=" + environment.evaluate(pmid);
			}

			if (!environment.evaluate(sa).equals("")) {
				urlstring = urlstring + "&sa=" + environment.evaluate(sa);
			}

			if (!environment.evaluate(species).equals("")) {
				urlstring = urlstring + "&species="
						+ environment.evaluate(species);
			}

			if (expandefo) {
				urlstring = urlstring + "&expandefo=on";
			}

			// create URL
			URL url = new URL(urlstring);

			// make connection
			URLConnection urlc = url.openConnection();

			// use post mode
			urlc.setDoOutput(true);
			urlc.setAllowUserInteraction(false);

			// send query
			PrintStream ps = new PrintStream(urlc.getOutputStream());
			ps.close();

			// get result
			BufferedReader br = new BufferedReader(new InputStreamReader(
					urlc.getInputStream()));
			StringBuilder result = new StringBuilder();
			String resultline = null;
			String lineseparator = System.getProperty("line.separator");
			while ((resultline = br.readLine()) != null) {
				result.append(resultline);
				result.append(lineseparator);
			}
			br.close();

			environment.getLocalContext().put(resultkey, result.toString());
			return Branches.DEFAULT;

		} catch (Exception e) {
			environment.getLocalContext().put("exception", e);
			return Branches.ERROR;
		}

	}

	/**
	 * Calls the Makenucseq Soapblab web service.
	 * 
	 * @param environment
	 * @param result
	 * @return
	 */
	public static String callMakenucseq(
			LightweightExecutionEnvironment environment,
			ContextExpressionFoundation amount,
			ContextExpressionFoundation length, ContextKeyFoundation result) {

		try {

			SoaplabBaseClient client = getClient("http://www.ebi.ac.uk/soaplab/services/edit.makenucseq");

			Map<String, Object> inputs = new HashMap<String, Object>();
			inputs.put("amount",
					((Integer) environment.evaluate(amount)).toString());
			inputs.put("length",
					((Integer) environment.evaluate(length)).toString());
			SoaplabMap results = client.runAndWaitFor(SoaplabMap
					.fromMap(inputs));
			Map<String, Object> outputs = SoaplabMap.toMap(results);

			environment.getLocalContext().put(result, outputs.get("outseq"));
			return Branches.DEFAULT;

		} catch (Exception e) {
			e.printStackTrace();
			environment.getLocalContext().put("exception", e);
			return Branches.ERROR;
		}

	}

	/**
	 * Calls the Makeprotseq Soapblab web service.
	 * 
	 * @param environment
	 * @param result
	 * @return
	 */
	public static String callMakeprotseq(
			LightweightExecutionEnvironment environment,
			ContextExpressionFoundation amount,
			ContextExpressionFoundation length, ContextKeyFoundation result) {

		try {

			SoaplabBaseClient client = getClient("http://www.ebi.ac.uk/soaplab/services/edit.makeprotseq");

			Map<String, Object> inputs = new HashMap<String, Object>();
			inputs.put("amount",
					((Integer) environment.evaluate(amount)).toString());
			inputs.put("length",
					((Integer) environment.evaluate(length)).toString());
			SoaplabMap results = client.runAndWaitFor(SoaplabMap
					.fromMap(inputs));
			Map<String, Object> outputs = SoaplabMap.toMap(results);

			environment.getLocalContext().put(result, outputs.get("outseq"));
			return Branches.DEFAULT;

		} catch (Exception e) {
			e.printStackTrace();
			environment.getLocalContext().put("exception", e);
			return Branches.ERROR;
		}

	}

	/**
	 * Calls the Getorf Soapblab web service.
	 * 
	 * @param environment
	 * @param sequence
	 * @param result
	 * @return
	 */
	public static String callGetorf(
			LightweightExecutionEnvironment environment,
			ContextExpressionFoundation sequence, ContextKeyFoundation result) {

		try {

			SoaplabBaseClient client = getClient("http://www.ebi.ac.uk/soaplab/services/nucleic_gene_finding.getorf");

			// SoaplabMap[] inputspecs = client.getInputSpec();
			// for (SoaplabMap inputspec : inputspecs){
			// Map<String, Object> entries = SoaplabMap.toMap(inputspec);
			// Set<String> keys = entries.keySet();
			// for (String key : keys){
			// System.out.println(key + " - " + entries.get(key));
			// }
			// }
			//

			Map<String, Object> inputs = new HashMap<String, Object>();
			inputs.put("sequence_direct_data", environment.evaluate(sequence));
			SoaplabMap results = client.runAndWaitFor(SoaplabMap
					.fromMap(inputs));
			Map<String, Object> outputs = SoaplabMap.toMap(results);

			environment.getLocalContext().put(result, outputs.get("outseq"));
			return Branches.DEFAULT;

		} catch (Exception e) {
			e.printStackTrace();
			environment.getLocalContext().put("exception", e);
			return Branches.ERROR;
		}

	}

	/**
	 * Calls the Emma Soapblab web service.
	 * 
	 * @param environment
	 * @param sequence
	 * @param result
	 * @return
	 */
	public static String callEmma(LightweightExecutionEnvironment environment,
			ContextExpressionFoundation sequence,
			ContextKeyFoundation resultAlignment,
			ContextKeyFoundation resultTree) {

		try {

			SoaplabBaseClient client = getClient("http://www.ebi.ac.uk/soaplab/services/alignment_multiple.emma");

			// SoaplabMap[] inputspecs = client.getInputSpec();
			// for (SoaplabMap inputspec : inputspecs){
			// Map<String, Object> entries = SoaplabMap.toMap(inputspec);
			// Set<String> keys = entries.keySet();
			// for (String key : keys){
			// System.out.println(key + " - " + entries.get(key));
			// }
			// }
			//

			Map<String, Object> inputs = new HashMap<String, Object>();
			inputs.put("sequence_direct_data", environment.evaluate(sequence));
			SoaplabMap results = client.runAndWaitFor(SoaplabMap
					.fromMap(inputs));
			Map<String, Object> outputs = SoaplabMap.toMap(results);

			environment.getLocalContext().put(resultAlignment,
					outputs.get("outseq"));
			environment.getLocalContext().put(resultTree,
					outputs.get("dendoutfile"));
			return Branches.DEFAULT;

		} catch (Exception e) {
			e.printStackTrace();
			environment.getLocalContext().put("exception", e);
			return Branches.ERROR;
		}

	}

	/**
	 * Calls the garnier Soapblab web service.
	 * 
	 * @param environment
	 * @param sequence
	 * @param result
	 * @return
	 */
	public static String callGarnier(
			LightweightExecutionEnvironment environment,
			ContextExpressionFoundation sequence, ContextKeyFoundation result) {

		try {

			SoaplabBaseClient client = getClient("http://www.ebi.ac.uk/soaplab/services/protein_2d_structure.garnier");

			// SoaplabMap[] inputspecs = client.getInputSpec();
			// for (SoaplabMap inputspec : inputspecs){
			// Map<String, Object> entries = SoaplabMap.toMap(inputspec);
			// Set<String> keys = entries.keySet();
			// for (String key : keys){
			// System.out.println(key + " - " + entries.get(key));
			// }
			// }
			//

			Map<String, Object> inputs = new HashMap<String, Object>();
			inputs.put("sequence_direct_data", environment.evaluate(sequence));
			SoaplabMap results = client.runAndWaitFor(SoaplabMap
					.fromMap(inputs));
			Map<String, Object> outputs = SoaplabMap.toMap(results);

			environment.getLocalContext().put(result, outputs.get("outfile"));
			return Branches.DEFAULT;

		} catch (Exception e) {
			e.printStackTrace();
			environment.getLocalContext().put("exception", e);
			return Branches.ERROR;
		}

	}

	/**
	 * Calls the scopparse Soapblab web service.
	 * 
	 * @param environment
	 * @param class
	 * @param des
	 * @param result
	 * @return
	 */
	public static String callScopparse(
			LightweightExecutionEnvironment environment,
			ContextExpressionFoundation classs,
			ContextExpressionFoundation des, ContextKeyFoundation result) {

		try {

			SoaplabBaseClient client = getClient("http://www.ebi.ac.uk/soaplab/services/utils_database_creation.scopparse");

			// SoaplabMap[] inputspecs = client.getInputSpec();
			// for (SoaplabMap inputspec : inputspecs) {
			// Map<String, Object> entries = SoaplabMap.toMap(inputspec);
			// Set<String> keys = entries.keySet();
			// for (String key : keys) {
			// System.out.println(key + " - " + entries.get(key));
			// }
			// }

			Map<String, Object> inputs = new HashMap<String, Object>();
			inputs.put("classfile_direct_data", environment.evaluate(classs));
			inputs.put("desinfile_direct_data", environment.evaluate(des));
			SoaplabMap results = client.runAndWaitFor(SoaplabMap
					.fromMap(inputs));
			Map<String, Object> outputs = SoaplabMap.toMap(results);

			environment.getLocalContext().put(result, outputs.get("dcffile"));
			return Branches.DEFAULT;

		} catch (Exception e) {
			e.printStackTrace();
			environment.getLocalContext().put("exception", e);
			return Branches.ERROR;
		}

	}

	/**
	 * Calls the ssematch Soapblab web service.
	 * 
	 * @param environment
	 * @param dcfnfile
	 * @param ssinfile
	 * @param result
	 * @return
	 */
	public static String callSsematch(
			LightweightExecutionEnvironment environment,
			ContextExpressionFoundation dcf, ContextExpressionFoundation ss,
			ContextKeyFoundation resultss, ContextKeyFoundation resultse) {

		try {

			SoaplabBaseClient client = getClient("http://www.ebi.ac.uk/soaplab/services/utils_database_creation.ssematch");

			SoaplabMap[] inputspecs = client.getInputSpec();
			for (SoaplabMap inputspec : inputspecs) {
				Map<String, Object> entries = SoaplabMap.toMap(inputspec);
				Set<String> keys = entries.keySet();
				for (String key : keys) {
					System.out.println(key + " - " + entries.get(key));
				}
			}

			Map<String, Object> inputs = new HashMap<String, Object>();
			inputs.put("dfinfile_direct_data", environment.evaluate(dcf));
			inputs.put("ssinfile_direct_data", environment.evaluate(ss));
			SoaplabMap results = client.runAndWaitFor(SoaplabMap
					.fromMap(inputs));
			Map<String, Object> outputs = SoaplabMap.toMap(results);

			environment.getLocalContext().put(resultss,
					outputs.get("outssfile"));
			environment.getLocalContext().put(resultss,
					outputs.get("outsefile"));
			return Branches.DEFAULT;

		} catch (Exception e) {
			e.printStackTrace();
			environment.getLocalContext().put("exception", e);
			return Branches.ERROR;
		}

	}

	private static SoaplabBaseClient getClient(String endpoint) {
		ServiceLocator locator = new ServiceLocator();
		locator.setProtocol(ClientConfig.PROTOCOL_AXIS1);
		locator.setServiceEndpoint(endpoint);
		try {
			return new SoaplabBaseClient(locator);
		} catch (SoaplabException e) {
			e.printStackTrace();
		}
		return null;
	}

	/**
	 * Calls the EBI's NCBI BLAST web service.
	 * 
	 * @param environment
	 * @param email
	 * @param title
	 * @param program
	 * @param matrix
	 * @param alignments
	 * @param scores
	 * @param exp
	 * @param dropoff
	 * @param match_scores
	 * @param gapopen
	 * @param gapext
	 * @param filter
	 * @param seqrange
	 * @param gapalign
	 * @param align
	 * @param stype
	 * @param sequence
	 * @param database
	 * @param resultkey
	 * @return
	 */
	public static String callNcbiBlast(
			LightweightExecutionEnvironment environment,
			ContextExpressionFoundation email,
			ContextExpressionFoundation title,
			ContextExpressionFoundation program,
			ContextExpressionFoundation matrix,
			ContextExpressionFoundation alignments,
			ContextExpressionFoundation scores,
			ContextExpressionFoundation exp,
			ContextExpressionFoundation dropoff,
			ContextExpressionFoundation match_scores,
			ContextExpressionFoundation gapopen,
			ContextExpressionFoundation gapext,
			ContextExpressionFoundation filter,
			ContextExpressionFoundation seqrange,
			ContextExpressionFoundation gapalign,
			ContextExpressionFoundation align,
			ContextExpressionFoundation stype,
			ContextExpressionFoundation sequence,
			ContextExpressionFoundation database,
			ContextKeyFoundation result_out,
			ContextKeyFoundation result_sequence,
			ContextKeyFoundation result_ids, ContextKeyFoundation result_xml) {

		try {

			// prepare service client
			NCBIBlastClient client = new NCBIBlastClient();
			InputParameters parameters = new InputParameters();

			// mandatory parameters
			parameters.setProgram((String) environment.evaluate(program));
			parameters.setDatabase(new String[] { (String) environment
					.evaluate(database) });
			parameters.setStype((String) environment.evaluate(stype));
			parameters.setSequence((String) environment.evaluate(sequence));

			// optional parameters
			if (!environment.evaluate(matrix).equals("")) {
				parameters.setMatrix((String) environment.evaluate(matrix));
			}
			if (!environment.evaluate(alignments).equals("")) {
				parameters.setAlignments((Integer) environment
						.evaluate(alignments));
			}
			if (!environment.evaluate(scores).equals("")) {
				parameters.setScores((Integer) environment.evaluate(scores));
			}
			if (!environment.evaluate(exp).equals("")) {
				parameters.setExp((String) environment.evaluate(exp));
			}
			if (!environment.evaluate(dropoff).equals("")) {
				parameters.setDropoff((Integer) environment.evaluate(dropoff));
			}
			if (!environment.evaluate(match_scores).equals("")) {
				parameters.setMatch_scores((String) environment
						.evaluate(match_scores));
			}
			if (!environment.evaluate(gapopen).equals("")) {
				parameters.setGapopen((Integer) environment.evaluate(gapopen));
			}
			if (!environment.evaluate(gapext).equals("")) {
				parameters.setGapext((Integer) environment.evaluate(gapext));
			}
			if (!environment.evaluate(filter).equals("")) {
				parameters.setFilter((String) environment.evaluate(filter));
			}
			if (!environment.evaluate(seqrange).equals("")) {
				parameters.setSeqrange((String) environment.evaluate(seqrange));
			}
			if (!environment.evaluate(gapalign).equals("")) {
				if (((String) environment.evaluate(gapalign))
						.equalsIgnoreCase("true")) {
					parameters.setGapalign(true);
				} else {
					parameters.setGapalign(false);
				}
			}
			if (!environment.evaluate(align).equals("")) {
				parameters.setAlign((Integer) environment.evaluate(align));
			}

			// WsParameterDetails paramdetails =
			// client.getParamDetail("database");
			// WsParameterValue[] values = paramdetails.getValues();
			// for (int i = 0; i<values.length; i++){
			// System.out.println(values[i].getValue());
			// }
			//
			// paramdetails = client.getParamDetail("stype");
			// values = paramdetails.getValues();
			// for (int i = 0; i<values.length; i++){
			// System.out.println(values[i].getValue());
			// }

			// run job
			String jobid = client.runApp((String) environment.evaluate(email),
					(String) environment.evaluate(title), parameters);

			String status = client.checkStatus(jobid);
			while (status.equals("RUNNING")) {
				Thread.sleep(1000);
				System.out.print(".");
				status = client.checkStatus(jobid);
			}
			System.out.println();

			if (status.equals("ERROR")) {
				environment
						.getLocalContext()
						.put("exception",
								"An error occurred when attempting to get the job status.");
				return Branches.ERROR;
			}

			if (status.equals("FAILURE")) {
				environment.getLocalContext().put("exception",
						"The job failed.");
				return Branches.ERROR;
			}

			if (status.equals("NOT_FOUND")) {
				environment.getLocalContext().put("exception",
						"The job cannot be found.");
				return Branches.ERROR;
			}

			// WsResultType[] resulttypes = client.getResultTypes(jobid);
			//
			// for (int i=0; i<resulttypes.length; i++){
			// System.out.println(resulttypes[i].getIdentifier() + " - " +
			// resulttypes[i].getDescription() + " - " +
			// resulttypes[i].getFileSuffix());
			// }

			// get system properties
			String tmpdir = System.getProperty("java.io.tmpdir");
			String lineseparator = System.getProperty("line.separator");

			// get results
			String[] resultfiles = client.getResults(jobid, tmpdir + "/"
					+ jobid, null);

			// out
			BufferedReader reader = new BufferedReader(new FileReader(
					resultfiles[0]));
			StringBuilder result = new StringBuilder();
			String line = "";
			while ((line = reader.readLine()) != null) {
				result.append(line);
				result.append(lineseparator);
			}
			reader.close();
			environment.getLocalContext().put(result_out, result.toString());

			// sequence
			reader = new BufferedReader(new FileReader(resultfiles[1]));
			result = new StringBuilder();
			line = "";
			while ((line = reader.readLine()) != null) {
				result.append(line);
				result.append(lineseparator);
			}
			reader.close();
			environment.getLocalContext().put(result_sequence,
					result.toString());

			// ids
			reader = new BufferedReader(new FileReader(resultfiles[2]));
			result = new StringBuilder();
			line = "";
			while ((line = reader.readLine()) != null) {
				result.append(line);
				result.append(lineseparator);
			}
			reader.close();
			environment.getLocalContext().put(result_ids, result.toString());

			// xml
			reader = new BufferedReader(new FileReader(resultfiles[3]));
			result = new StringBuilder();
			line = "";
			while ((line = reader.readLine()) != null) {
				result.append(line);
				result.append(lineseparator);
			}
			reader.close();
			environment.getLocalContext().put(result_xml, result.toString());

			// also available: different images...

			return Branches.DEFAULT;

		} catch (Exception e) {
			environment.getLocalContext().put("exception", e);
			e.printStackTrace();
			return Branches.ERROR;
		}

	}

	/**
	 * Calls the EBI's WUBlast web service.
	 * 
	 * @param environment
	 * @param email
	 * @param title
	 * @param program
	 * @param exp
	 * @param alignments
	 * @param scores
	 * @param align
	 * @param matrix
	 * @param stats
	 * @param sensitivity
	 * @param topcombon
	 * @param viewfilter
	 * @param filter
	 * @param strand
	 * @param sort
	 * @param stype
	 * @param sequence
	 * @param database
	 * @param result_out
	 * @param result_sequence
	 * @param result_ids
	 * @param result_xml
	 * @return
	 */
	public static String callWuBlast(
			LightweightExecutionEnvironment environment,
			ContextExpressionFoundation email,
			ContextExpressionFoundation title,
			ContextExpressionFoundation program,
			ContextExpressionFoundation exp,
			ContextExpressionFoundation alignments,
			ContextExpressionFoundation scores,
			ContextExpressionFoundation align,
			ContextExpressionFoundation matrix,
			ContextExpressionFoundation stats,
			ContextExpressionFoundation sensitivity,
			ContextExpressionFoundation topcombon,
			ContextExpressionFoundation viewfilter,
			ContextExpressionFoundation filter,
			ContextExpressionFoundation strand,
			ContextExpressionFoundation sort,
			ContextExpressionFoundation stype,
			ContextExpressionFoundation sequence,
			ContextExpressionFoundation database,
			ContextKeyFoundation result_out, ContextKeyFoundation result_error,
			ContextKeyFoundation result_sequence,
			ContextKeyFoundation result_ids, ContextKeyFoundation result_xml) {

		try {

			// prepare service client
			WUBlastClient client = new WUBlastClient();
			uk.ac.ebi.webservices.axis1.stubs.wublast.InputParameters parameters = new uk.ac.ebi.webservices.axis1.stubs.wublast.InputParameters();

			// mandatory parameters
			parameters.setProgram((String) environment.evaluate(program));
			parameters.setDatabase(new String[] { (String) environment
					.evaluate(database) });
			parameters.setStype((String) environment.evaluate(stype));
			parameters.setSequence((String) environment.evaluate(sequence));

			// optional parameters
			if (!environment.evaluate(exp).equals("")) {
				parameters.setExp((String) environment.evaluate(exp));
			}
			if (!environment.evaluate(alignments).equals("")) {
				parameters.setAlignments((Integer) environment
						.evaluate(alignments));
			}
			if (!environment.evaluate(scores).equals("")) {
				parameters.setScores((Integer) environment.evaluate(scores));
			}
			if (!environment.evaluate(align).equals("")) {
				parameters.setAlign((Integer) environment.evaluate(align));
			}
			if (!environment.evaluate(matrix).equals("")) {
				parameters.setMatrix((String) environment.evaluate(matrix));
			}
			if (!environment.evaluate(stats).equals("")) {
				parameters.setStats((String) environment.evaluate(stats));
			}
			if (!environment.evaluate(sensitivity).equals("")) {
				parameters.setSensitivity((String) environment
						.evaluate(sensitivity));
			}
			if (!environment.evaluate(topcombon).equals("")) {
				parameters.setTopcombon((String) environment
						.evaluate(topcombon));
			}
			if (!environment.evaluate(viewfilter).equals("")) {
				if (((String) environment.evaluate(viewfilter))
						.equalsIgnoreCase("true")) {
					parameters.setViewfilter(true);
				} else {
					parameters.setViewfilter(false);
				}
			}
			if (!environment.evaluate(filter).equals("")) {
				parameters.setFilter((String) environment.evaluate(filter));
			}
			if (!environment.evaluate(strand).equals("")) {
				parameters.setStrand((String) environment.evaluate(strand));
			}
			if (!environment.evaluate(sort).equals("")) {
				parameters.setSort((String) environment.evaluate(sort));
			}

			// WsParameterDetails paramdetails =
			// client.getParamDetail("database");
			// WsParameterValue[] values = paramdetails.getValues();
			// for (int i = 0; i<values.length; i++){
			// System.out.println(values[i].getValue());
			// }
			//
			// paramdetails = client.getParamDetail("stype");
			// values = paramdetails.getValues();
			// for (int i = 0; i<values.length; i++){
			// System.out.println(values[i].getValue());
			// }

			// run job
			String jobid = client.runApp((String) environment.evaluate(email),
					(String) environment.evaluate(title), parameters);

			String status = client.checkStatus(jobid);
			while (status.equals("RUNNING")) {
				Thread.sleep(1000);
				System.out.print(".");
				status = client.checkStatus(jobid);
			}
			System.out.println();

			if (status.equals("ERROR")) {
				environment
						.getLocalContext()
						.put("exception",
								"An error occurred when attempting to get the job status.");
				return Branches.ERROR;
			}

			if (status.equals("FAILURE")) {
				environment.getLocalContext().put("exception",
						"The job failed.");
				return Branches.ERROR;
			}

			if (status.equals("NOT_FOUND")) {
				environment.getLocalContext().put("exception",
						"The job cannot be found.");
				return Branches.ERROR;
			}

			uk.ac.ebi.webservices.axis1.stubs.wublast.WsResultType[] resulttypes = client
					.getResultTypes(jobid);

			for (int i = 0; i < resulttypes.length; i++) {
				System.out.println(resulttypes[i].getIdentifier() + " - "
						+ resulttypes[i].getDescription() + " - "
						+ resulttypes[i].getFileSuffix());
			}

			// get system properties
			String tmpdir = System.getProperty("java.io.tmpdir");
			String lineseparator = System.getProperty("line.separator");

			// get results
			String[] resultfiles = client.getResults(jobid, tmpdir + "/"
					+ jobid, null);

			// out
			BufferedReader reader = new BufferedReader(new FileReader(
					resultfiles[0]));
			StringBuilder result = new StringBuilder();
			String line = "";
			while ((line = reader.readLine()) != null) {
				result.append(line);
				result.append(lineseparator);
			}
			reader.close();
			environment.getLocalContext().put(result_out, result.toString());

			// error
			reader = new BufferedReader(new FileReader(resultfiles[1]));
			result = new StringBuilder();
			line = "";
			while ((line = reader.readLine()) != null) {
				result.append(line);
				result.append(lineseparator);
			}
			reader.close();
			environment.getLocalContext().put(result_error, result.toString());

			// sequence
			reader = new BufferedReader(new FileReader(resultfiles[2]));
			result = new StringBuilder();
			line = "";
			while ((line = reader.readLine()) != null) {
				result.append(line);
				result.append(lineseparator);
			}
			reader.close();
			environment.getLocalContext().put(result_sequence,
					result.toString());

			// ids
			reader = new BufferedReader(new FileReader(resultfiles[3]));
			result = new StringBuilder();
			line = "";
			while ((line = reader.readLine()) != null) {
				result.append(line);
				result.append(lineseparator);
			}
			reader.close();
			environment.getLocalContext().put(result_ids, result.toString());

			// xml
			reader = new BufferedReader(new FileReader(resultfiles[4]));
			result = new StringBuilder();
			line = "";
			while ((line = reader.readLine()) != null) {
				result.append(line);
				result.append(lineseparator);
			}
			reader.close();
			environment.getLocalContext().put(result_xml, result.toString());

			// also available: different images...

			return Branches.DEFAULT;

		} catch (Exception e) {
			environment.getLocalContext().put("exception", e);
			e.printStackTrace();
			return Branches.ERROR;
		}

	}

	/**
	 * Call the EBI's ClustalW2 Phylogeny web service.
	 * 
	 * @param environment
	 * @param email
	 * @param title
	 * @param tree
	 * @param kimura
	 * @param tossgaps
	 * @param clustering
	 * @param pim
	 * @param sequence
	 * @param resultkey
	 * @return
	 */
	public static String callClustalwPhylogeny(
			LightweightExecutionEnvironment environment,
			ContextExpressionFoundation email,
			ContextExpressionFoundation title,
			ContextExpressionFoundation tree,
			ContextExpressionFoundation kimura,
			ContextExpressionFoundation tossgaps,
			ContextExpressionFoundation clustering,
			ContextExpressionFoundation pim,
			ContextExpressionFoundation sequence,
			ContextKeyFoundation resultOut,
			ContextKeyFoundation resultSequence, ContextKeyFoundation resultTree) {

		try {

			// prepare service client
			ClustalW2PhylogenyClient client = new ClustalW2PhylogenyClient();
			uk.ac.ebi.webservices.axis1.stubs.clustalw2phylogeny.InputParameters parameters = new uk.ac.ebi.webservices.axis1.stubs.clustalw2phylogeny.InputParameters();

			// mandatory parameters
			parameters.setSequence((String) environment.evaluate(sequence));

			// optional parameters
			if (!environment.evaluate(tree).equals("")) {
				parameters.setTree((String) environment.evaluate(tree));
			}
			if (!environment.evaluate(kimura).equals("")) {
				if (((String) environment.evaluate(kimura))
						.equalsIgnoreCase("true")) {
					parameters.setKimura(true);
				} else {
					parameters.setKimura(false);
				}
			}
			if (!environment.evaluate(tossgaps).equals("")) {
				if (((String) environment.evaluate(tossgaps))
						.equalsIgnoreCase("true")) {
					parameters.setTossgaps(true);
				} else {
					parameters.setTossgaps(false);
				}
			}
			if (!environment.evaluate(clustering).equals("")) {
				parameters.setClustering((String) environment
						.evaluate(clustering));
			}
			if (!environment.evaluate(pim).equals("")) {
				if (((String) environment.evaluate(pim))
						.equalsIgnoreCase("true")) {
					parameters.setPim(true);
				} else {
					parameters.setPim(false);
				}
			}

			// WsParameterDetails paramdetails =
			// client.getParamDetail("database");
			// WsParameterValue[] values = paramdetails.getValues();
			// for (int i = 0; i<values.length; i++){
			// System.out.println(values[i].getValue());
			// }
			//
			// paramdetails = client.getParamDetail("stype");
			// values = paramdetails.getValues();
			// for (int i = 0; i<values.length; i++){
			// System.out.println(values[i].getValue());
			// }

			// run job
			String jobid = client.runApp((String) environment.evaluate(email),
					(String) environment.evaluate(title), parameters);

			String status = client.checkStatus(jobid);
			while (status.equals("RUNNING")) {
				Thread.sleep(1000);
				System.out.print(".");
				status = client.checkStatus(jobid);
			}
			System.out.println();

			if (status.equals("ERROR")) {
				environment
						.getLocalContext()
						.put("exception",
								"An error occurred when attempting to get the job status.");
				return Branches.ERROR;
			}

			if (status.equals("FAILURE")) {
				environment.getLocalContext().put("exception",
						"The job failed.");
				return Branches.ERROR;
			}

			if (status.equals("NOT_FOUND")) {
				environment.getLocalContext().put("exception",
						"The job cannot be found.");
				return Branches.ERROR;
			}

			// uk.ac.ebi.webservices.axis1.stubs.clustalw2phylogeny.WsResultType[]
			// resulttypes = client.getResultTypes(jobid);
			//
			// for (int i=0; i<resulttypes.length; i++){
			// System.out.println(resulttypes[i].getIdentifier() + " - " +
			// resulttypes[i].getDescription() + " - " +
			// resulttypes[i].getFileSuffix());
			// }
			//

			// get system properties
			String tmpdir = System.getProperty("java.io.tmpdir");
			String lineseparator = System.getProperty("line.separator");

			// get results
			String[] resultfiles = client.getResults(jobid, tmpdir + "/"
					+ jobid, null);

			// out
			BufferedReader reader = new BufferedReader(new FileReader(
					resultfiles[0]));
			StringBuilder result = new StringBuilder();
			String line = "";
			while ((line = reader.readLine()) != null) {
				result.append(line);
				result.append(lineseparator);
			}
			reader.close();
			environment.getLocalContext().put(resultOut, result.toString());

			// sequence
			reader = new BufferedReader(new FileReader(resultfiles[1]));
			result = new StringBuilder();
			line = "";
			while ((line = reader.readLine()) != null) {
				result.append(line);
				result.append(lineseparator);
			}
			reader.close();
			environment.getLocalContext()
					.put(resultSequence, result.toString());

			// tree
			reader = new BufferedReader(new FileReader(resultfiles[2]));
			result = new StringBuilder();
			line = "";
			while ((line = reader.readLine()) != null) {
				result.append(line);
				result.append(lineseparator);
			}
			reader.close();
			environment.getLocalContext().put(resultTree, result.toString());

			return Branches.DEFAULT;

		} catch (Exception e) {
			environment.getLocalContext().put("exception", e);
			e.printStackTrace();
			return Branches.ERROR;
		}

	}

	/**
	 * Calls the EBI's PSI SEARCH web service
	 * 
	 * @param environment
	 * @param email
	 * @param title
	 * @param matrix
	 * @param gapopen
	 * @param gapext
	 * @param expthr
	 * @param mask
	 * @param psithr
	 * @param scores
	 * @param alignments
	 * @param scoreformat
	 * @param sequence
	 * @param database
	 * @param previousjobid
	 * @param selectedhits
	 * @param cpfile
	 * @param resultJobid
	 * @param result
	 * @return
	 */
	public static String callPsiSearch(
			LightweightExecutionEnvironment environment,
			ContextExpressionFoundation email,
			ContextExpressionFoundation title,
			ContextExpressionFoundation matrix,
			ContextExpressionFoundation gapopen,
			ContextExpressionFoundation gapext,
			ContextExpressionFoundation expthr,
			ContextExpressionFoundation mask,
			ContextExpressionFoundation psithr,
			ContextExpressionFoundation scores,
			ContextExpressionFoundation alignments,
			ContextExpressionFoundation scoreformat,
			ContextExpressionFoundation sequence,
			ContextExpressionFoundation database,
			ContextExpressionFoundation previousjobid,
			ContextExpressionFoundation selectedhits,
			ContextExpressionFoundation cpfile,
			ContextKeyFoundation resultJobid, ContextKeyFoundation resultOut,
			ContextKeyFoundation resultSequence,
			ContextKeyFoundation resultIds,
			ContextKeyFoundation resultPreselectedIds,
			ContextKeyFoundation resultXml) {

		try {

			// prepare service client
			PSISearchClient client = new PSISearchClient();
			uk.ac.ebi.webservices.axis1.stubs.psisearch.InputParameters parameters = new uk.ac.ebi.webservices.axis1.stubs.psisearch.InputParameters();

			// mandatory parameters
			parameters.setSequence((String) environment.evaluate(sequence));
			parameters.setDatabase((String) environment.evaluate(database));

			// optional parameters
			if (!environment.evaluate(matrix).equals("")) {
				parameters.setMatrix((String) environment.evaluate(matrix));
			}
			if (!environment.evaluate(gapopen).equals("")) {
				parameters.setGapopen((Integer) environment.evaluate(gapopen));
			}
			if (!environment.evaluate(gapext).equals("")) {
				parameters.setGapext((Integer) environment.evaluate(gapext));
			}
			if (!environment.evaluate(expthr).equals("")) {
				parameters.setExpthr((Double) environment.evaluate(expthr));
			}
			if (!environment.evaluate(mask).equals("")) {
				if (((String) environment.evaluate(mask))
						.equalsIgnoreCase("true")) {
					parameters.setMask(true);
				} else {
					parameters.setMask(false);
				}
			}
			if (!environment.evaluate(psithr).equals("")) {
				parameters.setPsithr((Double) environment.evaluate(psithr));
			}
			if (!environment.evaluate(scores).equals("")) {
				parameters.setScores((Integer) environment.evaluate(scores));
			}
			if (!environment.evaluate(alignments).equals("")) {
				parameters.setAlignments((Integer) environment
						.evaluate(alignments));
			}
			if (!environment.evaluate(scoreformat).equals("")) {
				parameters.setScoreformat((String) environment
						.evaluate(scoreformat));
			}
			if (!environment.evaluate(previousjobid).equals("")) {
				parameters.setPreviousjobid((String) environment
						.evaluate(previousjobid));
			}
			if (!environment.evaluate(selectedhits).equals("")) {
				parameters.setSelectedHits((byte[]) environment
						.evaluate(matrix));
			}
			if (!environment.evaluate(cpfile).equals("")) {
				parameters.setCpfile((byte[]) environment.evaluate(cpfile));
			}

			// WsParameterDetails paramdetails =
			// client.getParamDetail("database");
			// WsParameterValue[] values = paramdetails.getValues();
			// for (int i = 0; i<values.length; i++){
			// System.out.println(values[i].getValue());
			// }
			//
			// paramdetails = client.getParamDetail("stype");
			// values = paramdetails.getValues();
			// for (int i = 0; i<values.length; i++){
			// System.out.println(values[i].getValue());
			// }

			// run job
			String jobid = client.runApp((String) environment.evaluate(email),
					(String) environment.evaluate(title), parameters);
			environment.getLocalContext().put(resultJobid, jobid);

			String status = client.checkStatus(jobid);
			while (status.equals("RUNNING")) {
				Thread.sleep(1000);
				System.out.print(".");
				status = client.checkStatus(jobid);
			}
			System.out.println();

			if (status.equals("ERROR")) {
				environment
						.getLocalContext()
						.put("exception",
								"An error occurred when attempting to get the job status.");
				return Branches.ERROR;
			}

			if (status.equals("FAILURE")) {
				environment.getLocalContext().put("exception",
						"The job failed.");
				return Branches.ERROR;
			}

			if (status.equals("NOT_FOUND")) {
				environment.getLocalContext().put("exception",
						"The job cannot be found.");
				return Branches.ERROR;
			}

			// uk.ac.ebi.webservices.axis1.stubs.psisearch.WsResultType[]
			// resulttypes = client.getResultTypes(jobid);
			//
			// for (int i=0; i<resulttypes.length; i++){
			// System.out.println(resulttypes[i].getIdentifier() + " - " +
			// resulttypes[i].getDescription() + " - " +
			// resulttypes[i].getFileSuffix());
			// }
			//

			// get system properties
			String tmpdir = System.getProperty("java.io.tmpdir");
			String lineseparator = System.getProperty("line.separator");

			// get results
			String[] resultfiles = client.getResults(jobid, tmpdir + "/"
					+ jobid, null);

			// out
			BufferedReader reader = new BufferedReader(new FileReader(
					resultfiles[1]));
			StringBuilder result = new StringBuilder();
			String line = "";
			while ((line = reader.readLine()) != null) {
				result.append(line);
				result.append(lineseparator);
			}
			reader.close();
			environment.getLocalContext().put(resultOut, result.toString());

			// sequence
			reader = new BufferedReader(new FileReader(resultfiles[2]));
			result = new StringBuilder();
			line = "";
			while ((line = reader.readLine()) != null) {
				result.append(line);
				result.append(lineseparator);
			}
			reader.close();
			environment.getLocalContext()
					.put(resultSequence, result.toString());

			// ids
			reader = new BufferedReader(new FileReader(resultfiles[3]));
			result = new StringBuilder();
			line = "";
			while ((line = reader.readLine()) != null) {
				result.append(line);
				result.append(lineseparator);
			}
			reader.close();
			environment.getLocalContext().put(resultIds, result.toString());

			// preselected_ids
			reader = new BufferedReader(new FileReader(resultfiles[4]));
			result = new StringBuilder();
			line = "";
			while ((line = reader.readLine()) != null) {
				result.append(line);
				result.append(lineseparator);
			}
			reader.close();
			environment.getLocalContext().put(resultPreselectedIds,
					result.toString());

			// xml
			reader = new BufferedReader(new FileReader(resultfiles[5]));
			result = new StringBuilder();
			line = "";
			while ((line = reader.readLine()) != null) {
				result.append(line);
				result.append(lineseparator);
			}
			reader.close();
			environment.getLocalContext().put(resultXml, result.toString());

			return Branches.DEFAULT;

		} catch (Exception e) {
			environment.getLocalContext().put("exception", e);
			e.printStackTrace();
			return Branches.ERROR;
		}

	}

	/**
	 * Calls the EBI'S emboss pepinfo web service.
	 * 
	 * @param environment
	 * @param email
	 * @param title
	 * @param hwindow
	 * @param sequence
	 * @param resultkey
	 * @return
	 */
	public static String callPepinfo(
			LightweightExecutionEnvironment environment,
			ContextExpressionFoundation email,
			ContextExpressionFoundation title,
			ContextExpressionFoundation hwindow,
			ContextExpressionFoundation sequence, ContextKeyFoundation resultkey) {

		try {

			// prepare service client
			EmbossPepinfoClient client = new EmbossPepinfoClient();
			uk.ac.ebi.webservices.axis1.stubs.emboss.pepinfo.InputParameters parameters = new uk.ac.ebi.webservices.axis1.stubs.emboss.pepinfo.InputParameters();

			// mandatory parameters
			parameters.setSequence((String) environment.evaluate(sequence));

			// optional parameters
			if (!environment.evaluate(hwindow).equals("")) {
				parameters.setHwindow((Integer) environment.evaluate(hwindow));
			}

			// WsParameterDetails paramdetails =
			// client.getParamDetail("database");
			// WsParameterValue[] values = paramdetails.getValues();
			// for (int i = 0; i<values.length; i++){
			// System.out.println(values[i].getValue());
			// }
			//
			// paramdetails = client.getParamDetail("stype");
			// values = paramdetails.getValues();
			// for (int i = 0; i<values.length; i++){
			// System.out.println(values[i].getValue());
			// }

			// run job
			String jobid = client.runApp((String) environment.evaluate(email),
					(String) environment.evaluate(title), parameters);

			String status = client.checkStatus(jobid);
			while (status.equals("RUNNING")) {
				Thread.sleep(1000);
				System.out.print(".");
				status = client.checkStatus(jobid);
			}
			System.out.println();

			if (status.equals("ERROR")) {
				environment
						.getLocalContext()
						.put("exception",
								"An error occurred when attempting to get the job status.");
				return Branches.ERROR;
			}

			if (status.equals("FAILURE")) {
				environment.getLocalContext().put("exception",
						"The job failed.");
				return Branches.ERROR;
			}

			if (status.equals("NOT_FOUND")) {
				environment.getLocalContext().put("exception",
						"The job cannot be found.");
				return Branches.ERROR;
			}

			// uk.ac.ebi.webservices.axis1.stubs.emboss.pepinfo.WsResultType[]
			// resulttypes = client.getResultTypes(jobid);
			//
			// for (int i=0; i<resulttypes.length; i++){
			// System.out.println(resulttypes[i].getIdentifier() + " - " +
			// resulttypes[i].getDescription() + " - " +
			// resulttypes[i].getFileSuffix());
			// }

			// get system properties
			String tmpdir = System.getProperty("java.io.tmpdir");
			String lineseparator = System.getProperty("line.separator");

			// get results
			String[] resultfiles = client.getResults(jobid, tmpdir + "/"
					+ jobid, null);

			// out
			BufferedReader reader = new BufferedReader(new FileReader(
					resultfiles[0]));
			StringBuilder result = new StringBuilder();
			String line = "";
			while ((line = reader.readLine()) != null) {
				result.append(line);
				result.append(lineseparator);
			}
			reader.close();
			environment.getLocalContext().put(resultkey, result.toString());

			return Branches.DEFAULT;

		} catch (Exception e) {
			environment.getLocalContext().put("exception", e);
			e.printStackTrace();
			return Branches.ERROR;
		}

	}

	/**
	 * Calls the EBI's EMBOSS NEEDLE web service.
	 * 
	 * @param environment
	 * @param email
	 * @param title
	 * @param matrix
	 * @param gapopen
	 * @param gapextend
	 * @param endweight
	 * @param endopen
	 * @param endext
	 * @param format
	 * @param stype
	 * @param asequence
	 * @param bsequence
	 * @param resultOut
	 * @param resultAln
	 * @return
	 */
	public static String callNeedle(
			LightweightExecutionEnvironment environment,
			ContextExpressionFoundation email,
			ContextExpressionFoundation title,
			ContextExpressionFoundation matrix,
			ContextExpressionFoundation gapopen,
			ContextExpressionFoundation gapextend,
			ContextExpressionFoundation endweight,
			ContextExpressionFoundation endopen,
			ContextExpressionFoundation endext,
			ContextExpressionFoundation format,
			ContextExpressionFoundation stype,
			ContextExpressionFoundation asequence,
			ContextExpressionFoundation bsequence,
			ContextKeyFoundation resultOut, ContextKeyFoundation resultAln) {

		try {

			// prepare service client
			EmbossNeedleClient client = new EmbossNeedleClient();
			uk.ac.ebi.webservices.axis1.stubs.emboss.needle.InputParameters parameters = new uk.ac.ebi.webservices.axis1.stubs.emboss.needle.InputParameters();

			// mandatory parameters
			parameters.setAsequence((String) environment.evaluate(asequence));
			parameters.setBsequence((String) environment.evaluate(bsequence));

			// optional parameters
			if (!environment.evaluate(matrix).equals("")) {
				parameters.setMatrix((String) environment.evaluate(matrix));
			}

			if (!environment.evaluate(gapopen).equals("")) {
				parameters.setGapopen((Float) environment.evaluate(gapopen));
			}

			if (!environment.evaluate(gapextend).equals("")) {
				parameters.setGapext((Float) environment.evaluate(gapextend));
			}

			if (!environment.evaluate(endweight).equals("")) {
				if (((String) environment.evaluate(endweight))
						.equalsIgnoreCase("true")) {
					parameters.setEndweight(true);
				} else {
					parameters.setEndweight(false);
				}
			}

			if (!environment.evaluate(endopen).equals("")) {
				parameters.setEndopen((Float) environment.evaluate(endopen));
			}

			if (!environment.evaluate(endext).equals("")) {
				parameters.setEndextend((Float) environment.evaluate(endext));
			}

			if (!environment.evaluate(format).equals("")) {
				parameters.setFormat((String) environment.evaluate(format));
			}

			if (!environment.evaluate(stype).equals("")) {
				parameters.setStype((String) environment.evaluate(stype));
			}

			// WsParameterDetails paramdetails =
			// client.getParamDetail("database");
			// WsParameterValue[] values = paramdetails.getValues();
			// for (int i = 0; i<values.length; i++){
			// System.out.println(values[i].getValue());
			// }
			//
			// paramdetails = client.getParamDetail("stype");
			// values = paramdetails.getValues();
			// for (int i = 0; i<values.length; i++){
			// System.out.println(values[i].getValue());
			// }

			// run job
			String jobid = client.runApp((String) environment.evaluate(email),
					(String) environment.evaluate(title), parameters);

			String status = client.checkStatus(jobid);
			while (status.equals("RUNNING")) {
				Thread.sleep(1000);
				System.out.print(".");
				status = client.checkStatus(jobid);
			}
			System.out.println();

			if (status.equals("ERROR")) {
				environment
						.getLocalContext()
						.put("exception",
								"An error occurred when attempting to get the job status.");
				return Branches.ERROR;
			}

			if (status.equals("FAILURE")) {
				environment.getLocalContext().put("exception",
						"The job failed.");
				return Branches.ERROR;
			}

			if (status.equals("NOT_FOUND")) {
				environment.getLocalContext().put("exception",
						"The job cannot be found.");
				return Branches.ERROR;
			}

			// uk.ac.ebi.webservices.axis1.stubs.emboss.needle.WsResultType[]
			// resulttypes = client.getResultTypes(jobid);
			//
			// for (int i=0; i<resulttypes.length; i++){
			// System.out.println(resulttypes[i].getIdentifier() + " - " +
			// resulttypes[i].getDescription() + " - " +
			// resulttypes[i].getFileSuffix());
			// }

			// get system properties
			String tmpdir = System.getProperty("java.io.tmpdir");
			String lineseparator = System.getProperty("line.separator");

			// get results
			String[] resultfiles = client.getResults(jobid, tmpdir + "/"
					+ jobid, null);

			// out
			BufferedReader reader = new BufferedReader(new FileReader(
					resultfiles[0]));
			StringBuilder result = new StringBuilder();
			String line = "";
			while ((line = reader.readLine()) != null) {
				result.append(line);
				result.append(lineseparator);
			}
			reader.close();
			environment.getLocalContext().put(resultOut, result.toString());

			// aln
			reader = new BufferedReader(new FileReader(resultfiles[3]));
			result = new StringBuilder();
			line = "";
			while ((line = reader.readLine()) != null) {
				result.append(line);
				result.append(lineseparator);
			}
			reader.close();
			environment.getLocalContext().put(resultAln, result.toString());

			return Branches.DEFAULT;

		} catch (Exception e) {
			environment.getLocalContext().put("exception", e);
			e.printStackTrace();
			return Branches.ERROR;
		}

	}

	/**
	 * Calls the EBI's EMBOSS WATER web service.
	 * 
	 * @param environment
	 * @param email
	 * @param title
	 * @param matrix
	 * @param gapopen
	 * @param gapext
	 * @param format
	 * @param stype
	 * @param asequence
	 * @param bsequence
	 * @param resultOut
	 * @param resultAln
	 * @return
	 */
	public static String callWater(LightweightExecutionEnvironment environment,
			ContextExpressionFoundation email,
			ContextExpressionFoundation title,
			ContextExpressionFoundation matrix,
			ContextExpressionFoundation gapopen,
			ContextExpressionFoundation gapext,
			ContextExpressionFoundation format,
			ContextExpressionFoundation stype,
			ContextExpressionFoundation asequence,
			ContextExpressionFoundation bsequence,
			ContextKeyFoundation resultOut, ContextKeyFoundation resultAln) {

		try {

			// prepare service client
			EmbossWaterClient client = new EmbossWaterClient();
			uk.ac.ebi.webservices.axis1.stubs.emboss.water.InputParameters parameters = new uk.ac.ebi.webservices.axis1.stubs.emboss.water.InputParameters();

			// mandatory parameters
			parameters.setAsequence((String) environment.evaluate(asequence));
			parameters.setBsequence((String) environment.evaluate(bsequence));

			// optional parameters
			if (!environment.evaluate(matrix).equals("")) {
				parameters.setMatrix((String) environment.evaluate(matrix));
			}

			if (!environment.evaluate(gapopen).equals("")) {
				parameters.setGapopen((Float) environment.evaluate(gapopen));
			}

			if (!environment.evaluate(format).equals("")) {
				parameters.setFormat((String) environment.evaluate(format));
			}

			if (!environment.evaluate(stype).equals("")) {
				parameters.setStype((String) environment.evaluate(stype));
			}

			// WsParameterDetails paramdetails =
			// client.getParamDetail("database");
			// WsParameterValue[] values = paramdetails.getValues();
			// for (int i = 0; i<values.length; i++){
			// System.out.println(values[i].getValue());
			// }
			//
			// paramdetails = client.getParamDetail("stype");
			// values = paramdetails.getValues();
			// for (int i = 0; i<values.length; i++){
			// System.out.println(values[i].getValue());
			// }

			// run job
			String jobid = client.runApp((String) environment.evaluate(email),
					(String) environment.evaluate(title), parameters);

			String status = client.checkStatus(jobid);
			while (status.equals("RUNNING")) {
				Thread.sleep(1000);
				System.out.print(".");
				status = client.checkStatus(jobid);
			}
			System.out.println();

			if (status.equals("ERROR")) {
				environment
						.getLocalContext()
						.put("exception",
								"An error occurred when attempting to get the job status.");
				return Branches.ERROR;
			}

			if (status.equals("FAILURE")) {
				environment.getLocalContext().put("exception",
						"The job failed.");
				return Branches.ERROR;
			}

			if (status.equals("NOT_FOUND")) {
				environment.getLocalContext().put("exception",
						"The job cannot be found.");
				return Branches.ERROR;
			}

			// uk.ac.ebi.webservices.axis1.stubs.emboss.water.WsResultType[]
			// resulttypes = client.getResultTypes(jobid);
			//
			// for (int i=0; i<resulttypes.length; i++){
			// System.out.println(resulttypes[i].getIdentifier() + " - " +
			// resulttypes[i].getDescription() + " - " +
			// resulttypes[i].getFileSuffix());
			// }

			// get system properties
			String tmpdir = System.getProperty("java.io.tmpdir");
			String lineseparator = System.getProperty("line.separator");

			// get results
			String[] resultfiles = client.getResults(jobid, tmpdir + "/"
					+ jobid, null);

			// out
			BufferedReader reader = new BufferedReader(new FileReader(
					resultfiles[0]));
			StringBuilder result = new StringBuilder();
			String line = "";
			while ((line = reader.readLine()) != null) {
				result.append(line);
				result.append(lineseparator);
			}
			reader.close();
			environment.getLocalContext().put(resultOut, result.toString());

			// aln
			reader = new BufferedReader(new FileReader(resultfiles[3]));
			result = new StringBuilder();
			line = "";
			while ((line = reader.readLine()) != null) {
				result.append(line);
				result.append(lineseparator);
			}
			reader.close();
			environment.getLocalContext().put(resultAln, result.toString());

			return Branches.DEFAULT;

		} catch (Exception e) {
			environment.getLocalContext().put("exception", e);
			e.printStackTrace();
			return Branches.ERROR;
		}

	}

	/**
	 * Calls the EBI's EMBOSS TRANSEQ web service.
	 * 
	 * @param environment
	 * @param email
	 * @param title
	 * @param frame
	 * @param codontable
	 * @param regions
	 * @param trim
	 * @param reverse
	 * @param sequence
	 * @param result
	 * @return
	 */
	public static String callTranseq(
			LightweightExecutionEnvironment environment,
			ContextExpressionFoundation email,
			ContextExpressionFoundation title,
			ContextExpressionFoundation frame,
			ContextExpressionFoundation codontable,
			ContextExpressionFoundation regions,
			ContextExpressionFoundation trim,
			ContextExpressionFoundation reverse,
			ContextExpressionFoundation sequence, ContextKeyFoundation result) {

		try {

			// prepare service client
			EmbossTranseqClient client = new EmbossTranseqClient();
			uk.ac.ebi.webservices.axis1.stubs.emboss.transeq.InputParameters parameters = new uk.ac.ebi.webservices.axis1.stubs.emboss.transeq.InputParameters();

			// mandatory parameters
			parameters.setSequence((String) environment.evaluate(sequence));

			// optional parameters
			if (!environment.evaluate(frame).equals("")) {
				parameters.setFrame((String) environment.evaluate(frame));
			}

			if (!environment.evaluate(codontable).equals("")) {
				parameters.setCodontable((String) environment
						.evaluate(codontable));
			}

			if (!environment.evaluate(regions).equals("")) {
				parameters.setRegions((String) environment.evaluate(regions));
			}

			if (!environment.evaluate(trim).equals("")) {
				if (((String) environment.evaluate(trim))
						.equalsIgnoreCase("true")) {
					parameters.setTrim(true);
				} else {
					parameters.setTrim(false);
				}
			}

			if (!environment.evaluate(reverse).equals("")) {
				if (((String) environment.evaluate(reverse))
						.equalsIgnoreCase("true")) {
					parameters.setReverse(true);
				} else {
					parameters.setReverse(false);
				}
			}
			// WsParameterDetails paramdetails =
			// client.getParamDetail("database");
			// WsParameterValue[] values = paramdetails.getValues();
			// for (int i = 0; i<values.length; i++){
			// System.out.println(values[i].getValue());
			// }
			//
			// paramdetails = client.getParamDetail("stype");
			// values = paramdetails.getValues();
			// for (int i = 0; i<values.length; i++){
			// System.out.println(values[i].getValue());
			// }

			// run job
			String jobid = client.runApp((String) environment.evaluate(email),
					(String) environment.evaluate(title), parameters);

			String status = client.checkStatus(jobid);
			while (status.equals("RUNNING")) {
				Thread.sleep(1000);
				System.out.print(".");
				status = client.checkStatus(jobid);
			}
			System.out.println();

			if (status.equals("ERROR")) {
				environment
						.getLocalContext()
						.put("exception",
								"An error occurred when attempting to get the job status.");
				return Branches.ERROR;
			}

			if (status.equals("FAILURE")) {
				environment.getLocalContext().put("exception",
						"The job failed.");
				return Branches.ERROR;
			}

			if (status.equals("NOT_FOUND")) {
				environment.getLocalContext().put("exception",
						"The job cannot be found.");
				return Branches.ERROR;
			}

			// uk.ac.ebi.webservices.axis1.stubs.emboss.transeq.WsResultType[]
			// resulttypes = client.getResultTypes(jobid);
			//
			// for (int i=0; i<resulttypes.length; i++){
			// System.out.println(resulttypes[i].getIdentifier() + " - " +
			// resulttypes[i].getDescription() + " - " +
			// resulttypes[i].getFileSuffix());
			// }

			// get system properties
			String tmpdir = System.getProperty("java.io.tmpdir");
			String lineseparator = System.getProperty("line.separator");

			// get results
			String[] resultfiles = client.getResults(jobid, tmpdir + "/"
					+ jobid, null);

			// out
			BufferedReader reader = new BufferedReader(new FileReader(
					resultfiles[0]));
			StringBuilder resultt = new StringBuilder();
			String line = "";
			while ((line = reader.readLine()) != null) {
				resultt.append(line);
				resultt.append(lineseparator);
			}
			reader.close();
			environment.getLocalContext().put(result, resultt.toString());

			// // aln
			// reader = new BufferedReader(new FileReader(resultfiles[3]));
			// result = new StringBuilder();
			// line = "";
			// while ((line = reader.readLine()) != null) {
			// result.append(line);
			// result.append(lineseparator);
			// }
			// reader.close();
			// environment.getLocalContext().put(resultAln, result.toString());

			return Branches.DEFAULT;

		} catch (Exception e) {
			environment.getLocalContext().put("exception", e);
			e.printStackTrace();
			return Branches.ERROR;
		}

	}

	/**
	 * Calls the EBI's EMBOSS BACKTRANSEQ web service (opposite of TRANSEQ
	 * service).
	 * 
	 * @param environment
	 * @param email
	 * @param title
	 * @param codontable
	 *            - Codon usage table name.
	 * @param sequence
	 *            - Input protein sequence.
	 * @param result
	 * @return
	 */
	public static String callBacktranseq(
			LightweightExecutionEnvironment environment,
			ContextExpressionFoundation email,
			ContextExpressionFoundation title,
			ContextExpressionFoundation codontable,
			ContextExpressionFoundation sequence, ContextKeyFoundation result) {

		try {

			// prepare service client
			EmbossBacktranseqClient client = new EmbossBacktranseqClient();
			uk.ac.ebi.webservices.axis1.stubs.emboss.backtranseq.InputParameters parameters = new uk.ac.ebi.webservices.axis1.stubs.emboss.backtranseq.InputParameters();

			// mandatory parameters
			parameters.setSequence((String) environment.evaluate(sequence));

			// optional parameters
			if (!environment.evaluate(codontable).equals("")) {
				parameters.setCodontable((String) environment
						.evaluate(codontable));
			}

			// WsParameterDetails paramdetails =
			// client.getParamDetail("database");
			// WsParameterValue[] values = paramdetails.getValues();
			// for (int i = 0; i<values.length; i++){
			// System.out.println(values[i].getValue());
			// }
			//
			// paramdetails = client.getParamDetail("stype");
			// values = paramdetails.getValues();
			// for (int i = 0; i<values.length; i++){
			// System.out.println(values[i].getValue());
			// }

			// run job
			String jobid = client.runApp((String) environment.evaluate(email),
					(String) environment.evaluate(title), parameters);

			String status = client.checkStatus(jobid);
			while (status.equals("RUNNING")) {
				Thread.sleep(1000);
				System.out.print(".");
				status = client.checkStatus(jobid);
			}
			System.out.println();

			if (status.equals("ERROR")) {
				environment
						.getLocalContext()
						.put("exception",
								"An error occurred when attempting to get the job status.");
				return Branches.ERROR;
			}

			if (status.equals("FAILURE")) {
				environment.getLocalContext().put("exception",
						"The job failed.");
				return Branches.ERROR;
			}

			if (status.equals("NOT_FOUND")) {
				environment.getLocalContext().put("exception",
						"The job cannot be found.");
				return Branches.ERROR;
			}

			// uk.ac.ebi.webservices.axis1.stubs.emboss.transeq.WsResultType[]
			// resulttypes = client.getResultTypes(jobid);
			//
			// for (int i=0; i<resulttypes.length; i++){
			// System.out.println(resulttypes[i].getIdentifier() + " - " +
			// resulttypes[i].getDescription() + " - " +
			// resulttypes[i].getFileSuffix());
			// }

			// get system properties
			String tmpdir = System.getProperty("java.io.tmpdir");
			String lineseparator = System.getProperty("line.separator");

			// get results
			String[] resultfiles = client.getResults(jobid, tmpdir + "/"
					+ jobid, null);

			// out
			BufferedReader reader = new BufferedReader(new FileReader(
					resultfiles[0]));
			StringBuilder resultt = new StringBuilder();
			String line = "";
			while ((line = reader.readLine()) != null) {
				resultt.append(line);
				resultt.append(lineseparator);
			}
			reader.close();
			environment.getLocalContext().put(result, resultt.toString());

			// // aln
			// reader = new BufferedReader(new FileReader(resultfiles[3]));
			// result = new StringBuilder();
			// line = "";
			// while ((line = reader.readLine()) != null) {
			// result.append(line);
			// result.append(lineseparator);
			// }
			// reader.close();
			// environment.getLocalContext().put(resultAln, result.toString());

			return Branches.DEFAULT;

		} catch (Exception e) {
			environment.getLocalContext().put("exception", e);
			e.printStackTrace();
			return Branches.ERROR;
		}

	}

	/**
	 * Calls the EBI's EMBOSS STRETCHER web service.
	 * 
	 * @param environment
	 * @param email
	 * @param title
	 * @param matrix
	 * @param gapopen
	 * @param gapext
	 * @param format
	 * @param stype
	 * @param asequence
	 * @param bsequence
	 * @param resultOut
	 * @param resultAln
	 * @return
	 */
	public static String callStretcher(
			LightweightExecutionEnvironment environment,
			ContextExpressionFoundation email,
			ContextExpressionFoundation title,
			ContextExpressionFoundation matrix,
			ContextExpressionFoundation gapopen,
			ContextExpressionFoundation gapext,
			ContextExpressionFoundation format,
			ContextExpressionFoundation stype,
			ContextExpressionFoundation asequence,
			ContextExpressionFoundation bsequence,
			ContextKeyFoundation resultOut, ContextKeyFoundation resultAln) {

		try {

			// prepare service client
			EmbossStretcherClient client = new EmbossStretcherClient();
			uk.ac.ebi.webservices.axis1.stubs.emboss.stretcher.InputParameters parameters = new uk.ac.ebi.webservices.axis1.stubs.emboss.stretcher.InputParameters();

			// mandatory parameters
			parameters.setAsequence((String) environment.evaluate(asequence));
			parameters.setBsequence((String) environment.evaluate(bsequence));

			// optional parameters
			if (!environment.evaluate(matrix).equals("")) {
				parameters.setMatrix((String) environment.evaluate(matrix));
			}

			if (!environment.evaluate(gapopen).equals("")) {
				parameters.setGapopen((Integer) environment.evaluate(gapopen));
			}

			if (!environment.evaluate(format).equals("")) {
				parameters.setFormat((String) environment.evaluate(format));
			}

			if (!environment.evaluate(stype).equals("")) {
				parameters.setStype((String) environment.evaluate(stype));
			}

			// WsParameterDetails paramdetails =
			// client.getParamDetail("database");
			// WsParameterValue[] values = paramdetails.getValues();
			// for (int i = 0; i<values.length; i++){
			// System.out.println(values[i].getValue());
			// }
			//
			// paramdetails = client.getParamDetail("stype");
			// values = paramdetails.getValues();
			// for (int i = 0; i<values.length; i++){
			// System.out.println(values[i].getValue());
			// }

			// run job
			String jobid = client.runApp((String) environment.evaluate(email),
					(String) environment.evaluate(title), parameters);

			String status = client.checkStatus(jobid);
			while (status.equals("RUNNING")) {
				Thread.sleep(1000);
				System.out.print(".");
				status = client.checkStatus(jobid);
			}
			System.out.println();

			if (status.equals("ERROR")) {
				environment
						.getLocalContext()
						.put("exception",
								"An error occurred when attempting to get the job status.");
				return Branches.ERROR;
			}

			if (status.equals("FAILURE")) {
				environment.getLocalContext().put("exception",
						"The job failed.");
				return Branches.ERROR;
			}

			if (status.equals("NOT_FOUND")) {
				environment.getLocalContext().put("exception",
						"The job cannot be found.");
				return Branches.ERROR;
			}

			// uk.ac.ebi.webservices.axis1.stubs.emboss.water.WsResultType[]
			// resulttypes = client.getResultTypes(jobid);
			//
			// for (int i=0; i<resulttypes.length; i++){
			// System.out.println(resulttypes[i].getIdentifier() + " - " +
			// resulttypes[i].getDescription() + " - " +
			// resulttypes[i].getFileSuffix());
			// }

			// get system properties
			String tmpdir = System.getProperty("java.io.tmpdir");
			String lineseparator = System.getProperty("line.separator");

			// get results
			String[] resultfiles = client.getResults(jobid, tmpdir + "/"
					+ jobid, null);

			// out
			BufferedReader reader = new BufferedReader(new FileReader(
					resultfiles[0]));
			StringBuilder result = new StringBuilder();
			String line = "";
			while ((line = reader.readLine()) != null) {
				result.append(line);
				result.append(lineseparator);
			}
			reader.close();
			environment.getLocalContext().put(resultOut, result.toString());

			// aln
			reader = new BufferedReader(new FileReader(resultfiles[3]));
			result = new StringBuilder();
			line = "";
			while ((line = reader.readLine()) != null) {
				result.append(line);
				result.append(lineseparator);
			}
			reader.close();
			environment.getLocalContext().put(resultAln, result.toString());

			return Branches.DEFAULT;

		} catch (Exception e) {
			environment.getLocalContext().put("exception", e);
			e.printStackTrace();
			return Branches.ERROR;
		}

	}

	/**
	 * Calls the EBI's EMBOSS WATER web service.
	 * 
	 * @param environment
	 * @param email
	 * @param alternatives
	 * @param title
	 * @param matrix
	 * @param gapopen
	 * @param gapext
	 * @param format
	 * @param stype
	 * @param asequence
	 * @param bsequence
	 * @param resultOut
	 * @param resultAln
	 * @return
	 */
	public static String callMatcher(
			LightweightExecutionEnvironment environment,
			ContextExpressionFoundation email,
			ContextExpressionFoundation alternatives,
			ContextExpressionFoundation title,
			ContextExpressionFoundation matrix,
			ContextExpressionFoundation gapopen,
			ContextExpressionFoundation gapext,
			ContextExpressionFoundation format,
			ContextExpressionFoundation stype,
			ContextExpressionFoundation asequence,
			ContextExpressionFoundation bsequence,
			ContextKeyFoundation resultOut, ContextKeyFoundation resultAln) {

		try {

			// prepare service client
			EmbossMatcherClient client = new EmbossMatcherClient();
			uk.ac.ebi.webservices.axis1.stubs.emboss.matcher.InputParameters parameters = new uk.ac.ebi.webservices.axis1.stubs.emboss.matcher.InputParameters();

			// mandatory parameters
			parameters.setAsequence((String) environment.evaluate(asequence));
			parameters.setBsequence((String) environment.evaluate(bsequence));

			// optional parameters
			if (!environment.evaluate(matrix).equals("")) {
				parameters.setMatrix((String) environment.evaluate(matrix));
			}

			if (!environment.evaluate(alternatives).equals("")) {
				parameters.setAlternatives((Integer) environment
						.evaluate(alternatives));
			}

			if (!environment.evaluate(gapopen).equals("")) {
				parameters.setGapopen((Integer) environment.evaluate(gapopen));
			}

			if (!environment.evaluate(format).equals("")) {
				parameters.setFormat((String) environment.evaluate(format));
			}

			if (!environment.evaluate(stype).equals("")) {
				parameters.setStype((String) environment.evaluate(stype));
			}

			// WsParameterDetails paramdetails =
			// client.getParamDetail("database");
			// WsParameterValue[] values = paramdetails.getValues();
			// for (int i = 0; i<values.length; i++){
			// System.out.println(values[i].getValue());
			// }
			//
			// paramdetails = client.getParamDetail("stype");
			// values = paramdetails.getValues();
			// for (int i = 0; i<values.length; i++){
			// System.out.println(values[i].getValue());
			// }

			// run job
			String jobid = client.runApp((String) environment.evaluate(email),
					(String) environment.evaluate(title), parameters);

			String status = client.checkStatus(jobid);
			while (status.equals("RUNNING")) {
				Thread.sleep(1000);
				System.out.print(".");
				status = client.checkStatus(jobid);
			}
			System.out.println();

			if (status.equals("ERROR")) {
				environment
						.getLocalContext()
						.put("exception",
								"An error occurred when attempting to get the job status.");
				return Branches.ERROR;
			}

			if (status.equals("FAILURE")) {
				environment.getLocalContext().put("exception",
						"The job failed.");
				return Branches.ERROR;
			}

			if (status.equals("NOT_FOUND")) {
				environment.getLocalContext().put("exception",
						"The job cannot be found.");
				return Branches.ERROR;
			}

			// uk.ac.ebi.webservices.axis1.stubs.emboss.water.WsResultType[]
			// resulttypes = client.getResultTypes(jobid);
			//
			// for (int i=0; i<resulttypes.length; i++){
			// System.out.println(resulttypes[i].getIdentifier() + " - " +
			// resulttypes[i].getDescription() + " - " +
			// resulttypes[i].getFileSuffix());
			// }

			// get system properties
			String tmpdir = System.getProperty("java.io.tmpdir");
			String lineseparator = System.getProperty("line.separator");

			// get results
			String[] resultfiles = client.getResults(jobid, tmpdir + "/"
					+ jobid, null);

			// out
			BufferedReader reader = new BufferedReader(new FileReader(
					resultfiles[0]));
			StringBuilder result = new StringBuilder();
			String line = "";
			while ((line = reader.readLine()) != null) {
				result.append(line);
				result.append(lineseparator);
			}
			reader.close();
			environment.getLocalContext().put(resultOut, result.toString());

			// aln
			reader = new BufferedReader(new FileReader(resultfiles[3]));
			result = new StringBuilder();
			line = "";
			while ((line = reader.readLine()) != null) {
				result.append(line);
				result.append(lineseparator);
			}
			reader.close();
			environment.getLocalContext().put(resultAln, result.toString());

			return Branches.DEFAULT;

		} catch (Exception e) {
			environment.getLocalContext().put("exception", e);
			e.printStackTrace();
			return Branches.ERROR;
		}

	}

	/**
	 * Calls the EBI's EMBOSS Pepwindow web service.
	 * 
	 * @param environment
	 * @param email
	 * @param title
	 * @param window
	 *            - Window size for hydropathy averaging.Default is 10.
	 * @param normalize
	 *            - Normalize data values. Default is false.
	 * @param sequence
	 *            - Protein sequence to analyse. The use of fasta formatted
	 *            sequence is recommended.
	 * @param result
	 *            - address of file with resulting graph
	 * @return - resulting branch
	 */
	public static String callPepwindow(
			LightweightExecutionEnvironment environment,
			ContextExpressionFoundation email,
			ContextExpressionFoundation title,
			ContextExpressionFoundation window,
			ContextExpressionFoundation normalize,
			ContextExpressionFoundation sequence, ContextKeyFoundation result) {
		try {

			// prepare service client
			EmbossPepwindowClient client = new EmbossPepwindowClient();
			uk.ac.ebi.webservices.axis1.stubs.emboss.pepwindow.InputParameters parameters = new uk.ac.ebi.webservices.axis1.stubs.emboss.pepwindow.InputParameters();

			// mandatory parameters
			parameters.setSequence((String) environment.evaluate(sequence));

			// optional parameters
			if (!environment.evaluate(window).equals("")) {
				parameters
						.setWindowsize((Integer) environment.evaluate(window));
			}

			if (!environment.evaluate(normalize).equals("")) {
				parameters.setNormalize((Boolean) environment
						.evaluate(normalize));
			}

			// WsParameterDetails paramdetails =
			// client.getParamDetail("database");
			// WsParameterValue[] values = paramdetails.getValues();
			// for (int i = 0; i<values.length; i++){
			// System.out.println(values[i].getValue());
			// }
			//
			// paramdetails = client.getParamDetail("stype");
			// values = paramdetails.getValues();
			// for (int i = 0; i<values.length; i++){
			// System.out.println(values[i].getValue());
			// }

			// run job
			String jobid = client.runApp((String) environment.evaluate(email),
					(String) environment.evaluate(title), parameters);

			String status = client.checkStatus(jobid);
			while (status.equals("RUNNING")) {
				Thread.sleep(1000);
				System.out.print(".");
				status = client.checkStatus(jobid);
			}
			System.out.println();

			if (status.equals("ERROR")) {
				environment
						.getLocalContext()
						.put("exception",
								"An error occurred when attempting to get the job status.");
				return Branches.ERROR;
			}

			if (status.equals("FAILURE")) {
				environment.getLocalContext().put("exception",
						"The job failed.");
				return Branches.ERROR;
			}

			if (status.equals("NOT_FOUND")) {
				environment.getLocalContext().put("exception",
						"The job cannot be found.");
				return Branches.ERROR;
			}

			// uk.ac.ebi.webservices.axis1.stubs.emboss.water.WsResultType[]
			// resulttypes = client.getResultTypes(jobid);
			//
			// for (int i=0; i<resulttypes.length; i++){
			// System.out.println(resulttypes[i].getIdentifier() + " - " +
			// resulttypes[i].getDescription() + " - " +
			// resulttypes[i].getFileSuffix());
			// }

			// get system properties
			String tmpdir = System.getProperty("java.io.tmpdir");
			// String lineseparator = System.getProperty("line.separator");

			// get results
			String[] resultfiles = client.getResults(jobid, tmpdir + "/"
					+ jobid, null);

			String filename = resultfiles[2];

			environment.getLocalContext().put(result, filename);

			return Branches.DEFAULT;

		} catch (Exception e) {
			environment.getLocalContext().put("exception", e);
			e.printStackTrace();
			return Branches.ERROR;
		}
	}

	/**
	 * Calls the EBI's EMBOSS Backtranambig service. Backtranambig reads a protein
	 * sequence and writes the nucleic acid sequence it could have come from. It
	 * does this by using nucleotide ambiguity codes that represent all possible
	 * codons for each amino acid.
	 * 
	 * @param email - user email address
	 * 
	 * @param title - job title. Default is empty string.
	 * 
	 * @param codontable - Genetic code table to use.
	 * 
	 * @param sequence - Input sequence (protein).
	 * 
	 * @param result - resulting sequence.
	 **/
	public static String callBacktranambig(
			LightweightExecutionEnvironment environment,
			ContextExpressionFoundation email,
			ContextExpressionFoundation title,
			ContextExpressionFoundation codontable,
			ContextExpressionFoundation sequence, ContextKeyFoundation result) {

		try {
			// prepare service client
			EmbossBacktranambigClient client = new EmbossBacktranambigClient();
			uk.ac.ebi.webservices.axis1.stubs.emboss.backtranambig.InputParameters parameters = new uk.ac.ebi.webservices.axis1.stubs.emboss.backtranambig.InputParameters();

			// mandatory parameters
			parameters.setSequence((String) environment.evaluate(sequence));

			// optional parameters
			if (!environment.evaluate(codontable).equals("")) {
				parameters.setCodontable((String) environment
						.evaluate(codontable));
			}

			// run job
			String jobid = client.runApp((String) environment.evaluate(email),
					(String) environment.evaluate(title), parameters);

			String status = client.checkStatus(jobid);
			while (status.equals("RUNNING")) {
				Thread.sleep(1000);
				System.out.print(".");
				status = client.checkStatus(jobid);
			}
			System.out.println();

			if (status.equals("ERROR")) {
				environment
						.getLocalContext()
						.put("exception",
								"An error occurred when attempting to get the job status.");
				return Branches.ERROR;
			}

			if (status.equals("FAILURE")) {
				environment.getLocalContext().put("exception",
						"The job failed.");
				return Branches.ERROR;
			}

			if (status.equals("NOT_FOUND")) {
				environment.getLocalContext().put("exception",
						"The job cannot be found.");
				return Branches.ERROR;
			}

			// get system properties
			String tmpdir = System.getProperty("java.io.tmpdir");
			String lineseparator = System.getProperty("line.separator");

			// get results
			String[] resultfiles = client.getResults(jobid, tmpdir + "/"
					+ jobid, null);

			// out
			BufferedReader reader = new BufferedReader(new FileReader(
					resultfiles[0]));
			StringBuilder resultt = new StringBuilder();
			String line = "";
			while ((line = reader.readLine()) != null) {
				resultt.append(line);
				resultt.append(lineseparator);
			}
			reader.close();
			environment.getLocalContext().put(result, resultt.toString());

			return Branches.DEFAULT;
		} catch (Exception e) {
			environment.getLocalContext().put("exception", e);
			e.printStackTrace();
			return Branches.ERROR;
		}
	}

	public static String callReadseq(
			LightweightExecutionEnvironment environment,
			ContextExpressionFoundation email,
			ContextExpressionFoundation title,
			ContextExpressionFoundation inputformat,
			ContextExpressionFoundation outputformat,
			ContextExpressionFoundation outputcase,
			ContextExpressionFoundation reverse,
			ContextExpressionFoundation degap,
			ContextExpressionFoundation transymbol,
			ContextExpressionFoundation feature,
			ContextExpressionFoundation fthandle,
			ContextExpressionFoundation subrange,
			ContextExpressionFoundation sequence,
			ContextKeyFoundation result) {
		try {
			// prepare service client
			ReadseqClient client = new ReadseqClient();
			uk.ac.ebi.webservices.axis1.stubs.readseq.InputParameters parameters = new uk.ac.ebi.webservices.axis1.stubs.readseq.InputParameters();

			// mandatory parameters
			parameters.setSequence((String) environment.evaluate(sequence));

			// optional parameters
			if (!environment.evaluate(inputformat).equals("")) {
				parameters.setInputformat((Integer) environment
						.evaluate(inputformat));
			}

			if (!environment.evaluate(outputformat).equals("")) {
				parameters.setOutputformat((Integer) environment
						.evaluate(outputformat));
			}

			if (!environment.evaluate(outputcase).equals("")) {
				parameters.setOutputcase((String) environment
						.evaluate(outputcase));
			}

			if (!environment.evaluate(reverse).equals("")) {
				parameters.setReverse((Boolean) environment
						.evaluate(reverse));
			}

			if (!environment.evaluate(degap).equals("")) {
				parameters.setDegap((String) environment
						.evaluate(degap));
			}

			if (!environment.evaluate(transymbol).equals("")) {
				parameters.setTransymbol((String) environment
						.evaluate(transymbol));
			}

			if (!environment.evaluate(feature).equals("")) {
				String featureStr = (String) environment.evaluate(feature);
				String[] split = featureStr.split(",");
				parameters.setFeature(split);
			}

			if (!environment.evaluate(fthandle).equals("")) {
				parameters.setFthandle((String) environment
						.evaluate(fthandle));
			}
			
			if (!environment.evaluate(subrange).equals("")) {
				parameters.setSubrange((String) environment
						.evaluate(subrange));
			}

			// run job
			String jobid = client.runApp((String) environment.evaluate(email),
					(String) environment.evaluate(title), parameters);

			String status = client.checkStatus(jobid);
			while (status.equals("RUNNING")) {
				Thread.sleep(1000);
				System.out.print(".");
				status = client.checkStatus(jobid);
			}
			System.out.println();

			if (status.equals("ERROR")) {
				environment
						.getLocalContext()
						.put("exception",
								"An error occurred when attempting to get the job status.");
				return Branches.ERROR;
			}

			if (status.equals("FAILURE")) {
				environment.getLocalContext().put("exception",
						"The job failed.");
				return Branches.ERROR;
			}

			if (status.equals("NOT_FOUND")) {
				environment.getLocalContext().put("exception",
						"The job cannot be found.");
				return Branches.ERROR;
			}

			// get system properties
			String tmpdir = System.getProperty("java.io.tmpdir");
			String lineseparator = System.getProperty("line.separator");

			// get results
			String[] resultfiles = client.getResults(jobid, tmpdir + "/"
					+ jobid, null);

			// out
			BufferedReader reader = new BufferedReader(new FileReader(
					resultfiles[0]));
			StringBuilder resultt = new StringBuilder();
			String line = "";
			while ((line = reader.readLine()) != null) {
				resultt.append(line);
				resultt.append(lineseparator);
			}
			reader.close();
			environment.getLocalContext().put(result, resultt.toString());

//			WsParameterDetails paramDetail = client.getParamDetail("transymbol");
//			String resultat = paramDetail.getName() + paramDetail.getValues()[0].getLabel() + "#" + paramDetail.getValues()[0].getValue();
//			environment.getLocalContext().put(result, resultat );
			
			return Branches.DEFAULT;
		} catch (Exception e) {
			environment.getLocalContext().put("exception", e);
			e.printStackTrace();
			return Branches.ERROR;
		}
	}

	/**
	 * Calls the EBI's EMBOSS SIXPACK web service.
	 * 
 	 * @param environment
 	 * @param email
 	 * @param title
 	 * @param codontable
 	 * @param firstorf
 	 * @param lastorf
 	 * @param reverse
 	 * @param orfminsize
 	 * @param sequence
 	 * @param resultOut
 	 * @return
	 */

	public static String callSixpack(
			LightweightExecutionEnvironment environment,
			ContextExpressionFoundation email,
			ContextExpressionFoundation title,
			ContextExpressionFoundation codontable,
			ContextExpressionFoundation firstorf,
			ContextExpressionFoundation lastorf,
			ContextExpressionFoundation reverse,
			ContextExpressionFoundation orfminsize,
			ContextExpressionFoundation sequence,
			ContextKeyFoundation resultOut) {
		try {

			// prepare service client
			EmbossSixpackClient client = new EmbossSixpackClient();
			uk.ac.ebi.webservices.axis1.stubs.emboss.sixpack.InputParameters parameters = new uk.ac.ebi.webservices.axis1.stubs.emboss.sixpack.InputParameters();

			// mandatory parameters
			parameters.setSequence((String) environment.evaluate(sequence));

			// optional parameters
			if (!environment.evaluate(codontable).equals("")) {
				parameters.setCodontable((String) environment.evaluate(codontable));
			}
			
			if (!environment.evaluate(orfminsize).equals("")) {
				parameters.setCodontable((String) environment.evaluate(orfminsize));
			}

			if (!environment.evaluate(firstorf).equals("")) {
				parameters.setFirstorf((Boolean) environment.evaluate(firstorf));
			}
			
			if (!environment.evaluate(lastorf).equals("")) {
				parameters.setLastorf((Boolean) environment.evaluate(lastorf));
			}
			
			if (!environment.evaluate(reverse).equals("")) {
				parameters.setReverse((Boolean) environment.evaluate(reverse));
			}
			

			// run job
			String jobid = client.runApp((String) environment.evaluate(email),
					(String) environment.evaluate(title), parameters);

			String status = client.checkStatus(jobid);
			while (status.equals("RUNNING")) {
				Thread.sleep(1000);
				System.out.print(".");
				status = client.checkStatus(jobid);
			}
			System.out.println();

			if (status.equals("ERROR")) {
				environment
						.getLocalContext()
						.put("exception",
								"An error occurred when attempting to get the job status.");
				return Branches.ERROR;
			}

			if (status.equals("FAILURE")) {
				environment.getLocalContext().put("exception",
						"The job failed.");
				return Branches.ERROR;
			}

			if (status.equals("NOT_FOUND")) {
				environment.getLocalContext().put("exception",
						"The job cannot be found.");
				return Branches.ERROR;
			}

			// get system properties
			String tmpdir = System.getProperty("java.io.tmpdir");
			String lineseparator = System.getProperty("line.separator");

			// get results
			String[] resultfiles = client.getResults(jobid, tmpdir + "/"
					+ jobid, null);

			// out
			BufferedReader reader = new BufferedReader(new FileReader(
					resultfiles[0]));
			StringBuilder result = new StringBuilder();
			String line = "";
			while ((line = reader.readLine()) != null) {
				result.append(line);
				result.append(lineseparator);
			}
			reader.close();
			environment.getLocalContext().put(resultOut, result.toString());

			return Branches.DEFAULT;

		} catch (Exception e) {
			environment.getLocalContext().put("exception", e);
			e.printStackTrace();
			return Branches.ERROR;
		}
		
	}

	/**
	 * Calls the EBI's EMBOSS PEPSTATS web service.
	 * 
 	 * @param environment
 	 * @param email
 	 * @param title
 	 * @param termini
 	 * @param mono
 	 * @param sequence
 	 * @param resultOut
 	 * @return
	 */

	public static String callPepstats(
			LightweightExecutionEnvironment environment,
			ContextExpressionFoundation email,
			ContextExpressionFoundation title,
			ContextExpressionFoundation termini,
			ContextExpressionFoundation mono,
			ContextExpressionFoundation sequence,
			ContextKeyFoundation resultOut) {
		try {

			// prepare service client
			EmbossPepstatsClient client = new EmbossPepstatsClient();
			uk.ac.ebi.webservices.axis1.stubs.emboss.pepstats.InputParameters parameters = new uk.ac.ebi.webservices.axis1.stubs.emboss.pepstats.InputParameters();

			// mandatory parameters
			parameters.setSequence((String) environment.evaluate(sequence));

			// optional parameters
			if (!environment.evaluate(termini).equals("")) {
				parameters.setTermini((Boolean) environment.evaluate(termini));
			}
			
			if (!environment.evaluate(mono).equals("")) {
				parameters.setMono((Boolean) environment.evaluate(mono));
			}

			// run job
			String jobid = client.runApp((String) environment.evaluate(email),
					(String) environment.evaluate(title), parameters);

			String status = client.checkStatus(jobid);
			while (status.equals("RUNNING")) {
				Thread.sleep(1000);
				System.out.print(".");
				status = client.checkStatus(jobid);
			}
			System.out.println();

			if (status.equals("ERROR")) {
				environment
						.getLocalContext()
						.put("exception",
								"An error occurred when attempting to get the job status.");
				return Branches.ERROR;
			}

			if (status.equals("FAILURE")) {
				environment.getLocalContext().put("exception",
						"The job failed.");
				return Branches.ERROR;
			}

			if (status.equals("NOT_FOUND")) {
				environment.getLocalContext().put("exception",
						"The job cannot be found.");
				return Branches.ERROR;
			}

			// get system properties
			String tmpdir = System.getProperty("java.io.tmpdir");
			String lineseparator = System.getProperty("line.separator");

			// get results
			String[] resultfiles = client.getResults(jobid, tmpdir + "/"
					+ jobid, null);

			// out
			BufferedReader reader = new BufferedReader(new FileReader(
					resultfiles[0]));
			StringBuilder result = new StringBuilder();
			String line = "";
			while ((line = reader.readLine()) != null) {
				result.append(line);
				result.append(lineseparator);
			}
			reader.close();
			environment.getLocalContext().put(resultOut, result.toString());

			return Branches.DEFAULT;

		} catch (Exception e) {
			environment.getLocalContext().put("exception", e);
			e.printStackTrace();
			return Branches.ERROR;
		}
		
	}

	/**
	 * Calls the EBI's CLUSTAL OMEGA web service.
	 * 
 	 * @param environment
 	 * @param email
 	 * @param title
 	 * @param termini
 	 * @param mono
 	 * @param sequence
 	 * @param resultOut
 	 * @return
	 */

	public static String callClustalOmega (
			LightweightExecutionEnvironment environment,
			ContextExpressionFoundation email,
			ContextExpressionFoundation title,
			ContextExpressionFoundation stype,
			ContextExpressionFoundation guidetreeout,
			ContextExpressionFoundation dismatout,
			ContextExpressionFoundation dealign,
			ContextExpressionFoundation mbed,
			ContextExpressionFoundation mbediteration,
			ContextExpressionFoundation iterations,
			ContextExpressionFoundation gtiterations,
			ContextExpressionFoundation hmmiterations,
			ContextExpressionFoundation outfmt,
			ContextExpressionFoundation sequence,
			ContextKeyFoundation resultOut) {
		try {

			// prepare service client
			ClustalOClient client = new ClustalOClient();
			uk.ac.ebi.webservices.axis1.stubs.clustalo.InputParameters parameters = new uk.ac.ebi.webservices.axis1.stubs.clustalo.InputParameters();

			String oldSequence = (String) environment.evaluate(sequence);
			
			String newSequence = oldSequence.replaceAll(" ", System.getProperty("line.separator"));
			
			// mandatory parameters
			parameters.setSequence(newSequence);

			// optional parameters
			if (!environment.evaluate(stype).equals("")) {
				parameters.setStype((String) environment.evaluate(stype));
			}
			
			if (!environment.evaluate(guidetreeout).equals("")) {
				parameters.setGuidetreeout((Boolean) environment.evaluate(guidetreeout));
			}
			
			if (!environment.evaluate(dismatout).equals("")) {
				parameters.setDismatout((Boolean) environment.evaluate(dismatout));
			}

			if (!environment.evaluate(dealign).equals("")) {
				parameters.setDealign((Boolean) environment.evaluate(dealign));
			}

			if (!environment.evaluate(mbed).equals("")) {
				parameters.setMbed((Boolean) environment.evaluate(mbed));
			}

			if (!environment.evaluate(mbediteration).equals("")) {
				parameters.setMbediteration((Boolean) environment.evaluate(mbediteration));
			}
			
			if (!environment.evaluate(iterations).equals("")) {
				parameters.setIterations((Integer) environment.evaluate(iterations));
			}

			if (!environment.evaluate(gtiterations).equals("")) {
				parameters.setGtiterations((Integer) environment.evaluate(gtiterations));
			}

			if (!environment.evaluate(hmmiterations).equals("")) {
				parameters.setHmmiterations((Integer) environment.evaluate(hmmiterations));
			}

			if (!environment.evaluate(outfmt).equals("")) {
				parameters.setOutfmt((String) environment.evaluate(outfmt));
			}
			
			// run job
			String jobid = client.runApp((String) environment.evaluate(email),
					(String) environment.evaluate(title), parameters);

			String status = client.checkStatus(jobid);
			while (status.equals("RUNNING")) {
				Thread.sleep(1000);
				System.out.print(".");
				status = client.checkStatus(jobid);
			}
			System.out.println();

			if (status.equals("ERROR")) {
				environment
						.getLocalContext()
						.put("exception",
								"An error occurred when attempting to get the job status.");
				return Branches.ERROR;
			}

			if (status.equals("FAILURE")) {
				environment.getLocalContext().put("exception",
						"The job failed.");
				return Branches.ERROR;
			}

			if (status.equals("NOT_FOUND")) {
				environment.getLocalContext().put("exception",
						"The job cannot be found.");
				return Branches.ERROR;
			}

			// get system properties
			String tmpdir = System.getProperty("java.io.tmpdir");
			String lineseparator = System.getProperty("line.separator");

			// get results
			String[] resultfiles = client.getResults(jobid, tmpdir + "/"
					+ jobid, null);

			// out
			BufferedReader reader = new BufferedReader(new FileReader(
					resultfiles[0]));
			StringBuilder result = new StringBuilder();
			String line = "";
			while ((line = reader.readLine()) != null) {
				result.append(line);
				result.append(lineseparator);
			}
			reader.close();
			environment.getLocalContext().put(resultOut, result.toString());

			return Branches.DEFAULT;

		} catch (Exception e) {
			environment.getLocalContext().put("exception", e);
			e.printStackTrace();
			return Branches.ERROR;
		}
		
	}
}

